<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Train extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name','address','activity_time','cover_image','part_count','price','contact_tele','intro','attention','status','club_id','mentor_id'
    ];
    public function consumer(){
        return $this->belongsTo(Consumer::class);
    }
    public function club(){
        return $this->belongsTo(Club::class);
    }//加载俱乐部对应类
    public function mentor(){
        return $this->belongsTo(Mentor::class);
    }//加载负责人类
    public function keytodata($keyname){
        return collect($keyname)->map(function($key){
            if(  !is_string($this->$key) && !is_int($this->$key)){
                if(  $this->$key  instanceof Carbon){
                    return [$key=>$this->$key->toFormattedDateString()];
                }
                else{
                    if($key=='club'||$key=='mentor'){
                        return [$key=>$this->$key->name];
                    }
                    else{
                        return [$key=>$this->$key->name];
                    }
                }
            }
            return [$key=>$this->$key];
        })->collapse()->toArray();
    }
}